package com.atde._05_behavioral_design_patterns.command.remotecontrol;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.command.remotecontrol
 * @Author: Del
 * @CreateTime: 2025-06-25  20:26
 * @Description: 命令模式：创建命令对象，并设置命令接收者，调用命令对象，完成命令执行
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 创建电灯接收者
        LightReceiver light = new LightReceiver();

        // 创建电灯相关的开关命令
        LightOnCommand lightOnCommand = new LightOnCommand(light);
        LightOffCommand lightOffCommand = new LightOffCommand(light);

        // 创建遥控器
        RemoteController remoteController = new RemoteController();

        // 设置第一组命令
        remoteController.setCommand(0, lightOnCommand, lightOffCommand);

        remoteController.onButtonWasPushed(0);
        remoteController.offButtonWasPushed(0);
        remoteController.undoButtonWasPushed();

        // 创建电视接收者
        TVReceiver tv = new TVReceiver();
        // 创建电灯相关的命令
        TVOnCommand tvOnCommand = new TVOnCommand(tv);
        TVOffCommand tvOffCommand = new TVOffCommand(tv);

        // 设置第二组命令
        remoteController.setCommand(1, tvOnCommand, tvOffCommand);
        remoteController.onButtonWasPushed(1);
        remoteController.offButtonWasPushed(1);
        remoteController.undoButtonWasPushed();
    }
}
